//
//  GroupChatMsg.m
//  SportSocial
//
//  Created by yull on 15/1/3.
//  Copyright (c) 2015年 yull. All rights reserved.
//

#import "GroupChatMsg.h"

@implementation GroupChatMsg

+ (instancetype)groupChatMsgWithMsg:(ChatMsgBody *)msgBody
{
    GroupChatMsg *groupChatMsg = [[GroupChatMsg alloc] init];
    groupChatMsg.msgNum = msgBody.msgNum;
    groupChatMsg.sendId = msgBody.sendId;
    groupChatMsg.senderName = msgBody.senderName;
    groupChatMsg.content = msgBody.msg;
    groupChatMsg.decodeContent = msgBody.msg;
    groupChatMsg.createTime = msgBody.createTime;
    groupChatMsg.msgType = msgBody.msgType;
    groupChatMsg.msgSubType = msgBody.msgType;
    groupChatMsg.url = msgBody.url;
    groupChatMsg.bigImageUrl = msgBody.bigImageUrl;
    groupChatMsg.isAck = NO;
    groupChatMsg.isRead = groupChatMsg.msgType != ChatMsgTypeAudio;
    groupChatMsg.msgLength = 0;
    groupChatMsg.picUploadPercent = 0;
    groupChatMsg.retainField = @"";
    groupChatMsg.roleType = ChatMsgRoleTypeReceive;
    groupChatMsg.sendStatus = ChatMsgSendStatusSuccess;
    groupChatMsg.icon = msgBody.icon;
    
    groupChatMsg.audioRestTime = groupChatMsg.msgLength;
    groupChatMsg.audioStatus = ChatMsgAudioStatusNone;
    
    return groupChatMsg;
}

+ (instancetype)groupMsgWithResultSet:(FMResultSet *)resultSet
{
    GroupChatMsg *groupChatMsg = [[GroupChatMsg alloc] init];
    groupChatMsg.dbId = [resultSet longLongIntForColumn:@"id"];
    groupChatMsg.msgNum = [resultSet longLongIntForColumn:@"msgNum"];
    groupChatMsg.sendId = [resultSet longLongIntForColumn:@"sendId"];
    groupChatMsg.senderName = [resultSet stringForColumn:@"senderName"];
    groupChatMsg.groupId = [resultSet longLongIntForColumn:@"groupId"];
    groupChatMsg.content = [resultSet stringForColumn:@"content"];
    groupChatMsg.decodeContent = [resultSet stringForColumn:@"decodeContent"];
    groupChatMsg.createTime = [resultSet longLongIntForColumn:@"createTime"];
    groupChatMsg.msgType = [resultSet intForColumn:@"msgType"];
    groupChatMsg.msgSubType = [resultSet intForColumn:@"msgSubType"];
    groupChatMsg.url = [resultSet stringForColumn:@"url"];
    groupChatMsg.bigImageUrl = [resultSet stringForColumn:@"bigImageUrl"];
    groupChatMsg.isAck = [resultSet boolForColumn:@"isAck"];
    groupChatMsg.isRead = [resultSet boolForColumn:@"isRead"];
    groupChatMsg.msgLength = [resultSet intForColumn:@"msgLength"];
    groupChatMsg.picUploadPercent = [resultSet doubleForColumn:@"picUploadPercent"];
    groupChatMsg.localPath = [resultSet stringForColumn:@"localPath"];
    groupChatMsg.retainField = [resultSet stringForColumn:@"retainField"];
    groupChatMsg.roleType = [resultSet intForColumn:@"roleType"];
    groupChatMsg.sendStatus = [resultSet intForColumn:@"sendStatus"];
    groupChatMsg.icon = [resultSet stringForColumn:@"icon"];
    
    groupChatMsg.audioRestTime = groupChatMsg.msgLength;
    groupChatMsg.audioStatus = ChatMsgAudioStatusNone;
    return groupChatMsg;
}
@end
